package com.b2bpsssm.service.impl;

import com.b2bpsssm.common.R;
import com.b2bpsssm.mapper.OtherRevenueMapper;
import com.b2bpsssm.pojo.Other_Revenue;
import com.b2bpsssm.service.OtherRevenueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OtherRevenueServiceImpl  implements OtherRevenueService {
   @Autowired
   private OtherRevenueMapper otherRevenueMapper;
      //查询其他收入  带分页
    @Override
    public R queryOtherRevenueList(Integer currentPage, Integer pageSize) {
        R r = new R();
        Integer start = (currentPage - 1) * pageSize;//分页第一个参数
        Integer off = pageSize; //分页第二个参数
        //查询后的数据
        List<Other_Revenue> other_revenues = otherRevenueMapper.queryOtherRevenueList(start, off);
        //成功后返回的结果
        r.setCode(200);
        r.setMassage("success");
        r.setData(other_revenues);
        return r;
    }
    // 以收支类型关键字 时间范围 进行关键字查询
    @Override
    public R selOtherRevenueLikeType(Integer currentPage, Integer pageSize, String other_revenue_creation_time1, String other_revenue_creation_time2, String other_revenue_payment_type) {
        R r = new R();
        Integer start = (currentPage - 1) * pageSize;//分页第一个参数
        Integer off = pageSize; //分页第二个参数
        List<Other_Revenue> list = otherRevenueMapper.selOtherRevenueLikeType(start, off,other_revenue_creation_time1, other_revenue_creation_time2,other_revenue_payment_type);
        //成功后返回的结果
        r.setCode(200);
        r.setMassage("success");
        r.setData(list);

        return r;
    }

    @Override
    public R addOtherRevenue(Other_Revenue other_revenue) {
        R r = new R();
        try {
            int result = otherRevenueMapper.addOtherRevenue(other_revenue);
            if (result > 0) {
                r.setCode(200);
                r.setMassage("添加成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
            r.setCode(500);
            r.setMassage("系统开小差了，请联系管理员！");
        }
        return r;

    }

    @Override
    public R updateOtherRevenue(Other_Revenue other_revenue) {

        R r = new R();

        try {
            int result = otherRevenueMapper.updateOtherRevenue(other_revenue);
            if (result > 0) {
                r.setCode(200);
                r.setMassage("修改成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
            r.setCode(500);
            r.setMassage("系统开小差了，请联系管理员！");
        }
        return r;
    }
    //根据编号删除
    @Override
    public R delOtherRevenueByNumber(Other_Revenue other_revenue_bills) {
        R r = new R();

        try {
            int result = otherRevenueMapper.delOtherRevenueByNumber(other_revenue_bills);
            if (result > 0) {
                r.setCode(200);
                r.setMassage("删除成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
            r.setCode(500);
            r.setMassage("系统开小差了，请联系管理员！");
        }
        return r;
    }

}

